package com.jyxd.web.controller.czform;

import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.data.user.User;
import com.jyxd.web.service.czform.ECMOEstablishEndService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Api(tags = "ECMO建立与结束表接口")
@Controller
@RequestMapping(value = "/ecmoEstablishEnd")
public class ECMOEstablishEndController {

    @Autowired
    private ECMOEstablishEndService ecmoEstablishEndService;

    @ApiOperation("新增或者修改ECMO建立与结束表接口")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult saveOrUpdate(@RequestBody Map<String, Object> map, HttpSession session) {
        User user = (User) session.getAttribute("user");
        errorIfEmpty(user, "登录用户不存在");
        return ecmoEstablishEndService.saveOrUpdate(map, user.getUserName());
    }

    @ApiOperation("查询ECMO建立与结束表接口列表（可分页）")
    @RequestMapping(value = "/queryListByPatientId", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getListByRowId(@RequestBody Map<String, Object> map) {
        return ecmoEstablishEndService.getListByRowId(map);
    }

    @ApiOperation("查询ECMO建立与结束表接口单页数据")
    @RequestMapping(value = "/getData", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getData(@RequestBody Map<String, Object> map) {
        return ecmoEstablishEndService.getDataByByRowId(map);
    }

    @ApiOperation("删除整页数据")
    @RequestMapping(value = "/deleteData", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult deleteData(@RequestBody Map<String, Object> map) {
        String rowId = map.get("rowId").toString();
        return ecmoEstablishEndService.deleteData(rowId);
    }
}
